<?php

class CCache{

	public static function getCrawlMaxId(){ 
		$myCache = Zend_Registry::get('myCache');
		$maxCrawlId = $myCache->load('crawlMaxId');
		if(!$maxCrawlId){
			$crawl = new CCrawl();
			$maxCrawlId = $crawl->getMaxId();
			$myCache->save($maxCrawlId,'crawlMaxId');
		}
		return $maxCrawlId;
	}
	
	public static function getJingzhengwebsites(){
		return array("sparta7","9soccers","eurojerseys","soccerjerseyswholesaler","nationalsoccerjerseys","cnsoccerjersey","europe2012soccerjerseys","soccertriads","wincheapjerseys","uksoccersproshop","soccerbootsoutlet","customsoccerjerseystore","soccerjerseysalon","cheapsoccercleatsjerseys","cheapsoccerjerseys","9footballshirt","wholesalecheapjerseysgo","wholesalesoccer-jerseys","wholesalesoccerjerseys","cwholesalejerseys","iwholesalesoccers","totallysoccer","buywholesalesoccerjerseys","wholesalesoccershirt","soccerpro");
	}
	
	public static function getCombinlistItemMap(){
		$myCache = Zend_Registry::get('myCache');
		$itemMap = $myCache->load('combinlistItemMap');
		if(!$itemMap || count($itemMap) == 0){
			$where="is_showed=1 and zcshop_products.onsales=0";
			$itemShow=new CItemShow();
			$itemShow->setType('product');
			$itemShow->setWhere($where);
			$itemArray=$itemShow->getAllItems();
			$itemMap=array();
			foreach($itemArray as $item){
				$itemMap[$item['itemid']]=$item;
			}
			$myCache->save($itemMap,'combinlistItemMap');
		}
		return $itemMap;
	}
	
	public static function flushCombinlistItemMap(){
		$myCache = Zend_Registry::get('myCache');
		$where="is_showed=1 and zcshop_products.onsales=0 and min_price < max_price";
		$itemShow=new CItemShow();
		$itemShow->setType('product');
		$itemShow->setWhere($where);
		$itemArray=$itemShow->getAllItems();
		$itemMap=array();
		foreach($itemArray as $item){
			$itemMap[$item['itemid']]=$item;
		}
		$myCache->save($itemMap,'combinlistItemMap');
	}
	
	public static function getPlayerArray(){
		$myCache = Zend_Registry::get('myCache');
		$playerInfoArray = $myCache->load('playerInfoArray');
		if(!$playerInfoArray || count($playerInfoArray) == 0){
			$player = new CPlayer();
			$playerInfoArray = $player->getPlayerArray();
			$myCache->save($playerInfoArray,'playerInfoArray');
		}
		return $playerInfoArray;
	}
	
	public static function getHotItems(){
		$myCache = Zend_Registry::get('myCache');
		$hotItemArray = $myCache->load('hotItemProductsArray');
		if(!$hotItemArray || count($hotItemArray)==0){
			$where="is_showed=1 and zcshop_products.onsales=0";
	        $itemShow=new CItemShow();
	        $itemShow->setType('product');
	        $itemShow->setWhere($where);
	        $itemCounts=$itemShow->getAllItemCounts();
	        $itemShow->setFromTo(array('counts'=>24,'from'=>0));
	        $myorder = R_PRE."items.view_num DESC";
	        $itemShow->setOrder($myorder);
	        $hotItemArray=$itemShow->getAllItems();
	        $myCache->save($hotItemArray,'hotItemProductsArray');
		}
		return $hotItemArray;
	}
	
	public static function getBlackFridayKeyArray(){
		$blackFridayKeyArray = array('for Black Friday','for Christmas','for Thanksgiving Day','for X\'mas','Christmas Gift','X\'mas Gift');
		return $blackFridayKeyArray;
	}
	
	public static function getClientComments(){
		$myCache = Zend_Registry::get('myCache');
		$clientComments = $myCache->load('clientComments');
		if(!$clientComments){
			$suggestionModel=new CSuggestion();
			$clientComments=$suggestionModel->getAllContent(100, 0);
			$myCache->save($clientComments,'clientComments');
		}
		return $clientComments;
	}
	
	public static function getProductAttributeMap(){
		$myCache = Zend_Registry::get('myCache');
		$productAttributeMap = $myCache->load('productAttributeMap');
		if(!$productAttributeMap){
			$brandArray=array(1=>'Nike',2=>'Adidas',3=>'Umbro',4=>'Puma',5=>'Reebok',6=>'Kappa',7=>'Le coq sportif',8=>'XTEP',9=>'Lotto');
			$playerInfoArray = CCache::getPlayerArray();
			$playerArray = array();
			$id = 0;
			foreach($playerInfoArray as $playerInfo){
				$playerArray[$id]=$playerInfo['name'];
				$id++;
			}
			$categoryArray=array(1=>'Jersey Shirt',2=>'Jersey Kit (Shirt+Short)',3=>'Whole Jersey Kit (Shirt+Short+Socks)',3=>'Jacket & Tracksuit');
	        $productAttributeMap['Brand'] = $brandArray;
	        $productAttributeMap['Player'] = $playerArray;
	        $productAttributeMap['Category'] = $categoryArray;
	        $myCache->save($productAttributeMap,'productAttributeMap');
		}
		return $productAttributeMap;
	}
	
}